﻿<%@ Page 
    Language="C#" 
    AutoEventWireup="true" 
    CodeBehind="AlunoListar.aspx.cs" 
    Inherits="Arquitetura.UI.WebApp.AlunoListar" 
    MasterPageFile="~/Master/Default.Master"
    Theme="Default"
%>
<%@ Import
    Namespace="Arquitetura.Common"
%>
<asp:Content ContentPlaceHolderID="cphHead" runat="server">
</asp:Content>
<asp:Content ContentPlaceHolderID="cphContent" runat="server">
    <h1>
        Alunos
    </h1>
    <asp:UpdatePanel ID="upAlunoListar"
        runat="server"
        ChildrenAsTriggers="true"
        RenderMode="Inline"
        UpdateMode="Conditional">
        <ContentTemplate>
            <div class="Cadastro">
                <table>
                    <tr>
                        <td>
                            <label for="<%= txtNome.ClientID %>">
                                <asp:Label ID="lblNome" 
                                    runat="server"
                                    SkinID="TituloCampo" 
                                    Text="Nome:"/>
                            </label>
                        </td>
                        <td>
                            <asp:TextBox ID="txtNome"
                                runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="<%= txtSobrenome.ClientID %>">
                                <asp:Label ID="lblSobrenome" 
                                    runat="server"
                                    SkinID="TituloCampo" 
                                    Text="Sobrenome:"/>
                            </label>
                        </td>
                        <td>
                            <asp:TextBox ID="txtSobrenome"
                                runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td />
                        <td>
                            <asp:Button ID="btnFiltrar"
                                runat="server"
                                OnClick="btnPesquisar_Click"
                                Text="Pesquisar" />
                            <asp:Button ID="btnLimpar"
                                runat="server"
                                OnClick="btnLimpar_Click"
                                Text="Limpar" />              
                        </td>
                    </tr>
                </table>
            </div>
            <asp:ObjectDataSource ID="odsAlunos"
                runat="server" 
                EnablePaging="true"
                SortParameterName="sortExpression"
                SelectCountMethod="ContarAlunoFiltro"
                SelectMethod="ListarAlunoFiltro"
                TypeName="Arquitetura.UI.WebApp.AlunoHelper"
                DataObjectTypeName="Arquitetura.UI.WebApp.SecretariaServiceReference.Aluno"
                OnObjectCreating="odsAlunos_ObjectCreating"
                OnSelecting="odsAlunos_Selecting"
                OnSelected="odsAlunos_Selected"
                StartRowIndexParameterName="startRowIndex"
                MaximumRowsParameterName="maximumRows">
                <SelectParameters>
                    <asp:Parameter Name="alunoFiltro"
                        Type="Object" 
                        Direction="Input" />
                    <asp:Parameter Name="startRowIndex"
                        Type="Int32"
                        Direction="Input" />
                    <asp:Parameter Name="maximumRows"
                        Type="Int32"
                        Direction="Input" />
                    <asp:Parameter Name="sortExpression"
                        Type="String"
                        Direction="Input" />
                    <asp:Parameter Name="resultado"
                        Type="Object"
                        Direction="Output" />
                </SelectParameters>
            </asp:ObjectDataSource>
            <asp:GridView ID="grvAlunos"
                runat="server"
                AllowPaging="true"
                AllowSorting="true"
                PageSize="10"
                AutoGenerateColumns="false"
                DataSourceID="odsAlunos"
                EmptyDataText="Não foi encontrado nenhum aluno."
                OnPageIndexChanging="grvAlunos_PageIndexChanging"
                OnRowCommand="grvAlunos_RowCommand"
                SkinID="Grid">
                <Columns>
                    <asp:TemplateField 
                        HeaderText="Prontuário" 
                        SortExpression="Prontuario">
                        <ItemTemplate>
                            <%# Eval("Prontuario") %>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField 
                        HeaderText="Aluno"
                        SortExpression="Nome">
                        <ItemTemplate>
                            <%# Eval("Nome") + " " + Eval("Sobrenome") %>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField 
                        HeaderText="CPF"
                        SortExpression="CPF">
                        <ItemTemplate>
                            <%# Formata.FormataCPF((string)Eval("CPF")) %>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField 
                        HeaderText="RG"
                        SortExpression="RG">
                        <ItemTemplate>
                            <%# Eval("RG") %>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Nome da Mãe">
                        <ItemTemplate>
                            <%# Eval("Mae.Nome") + " " + Eval("Mae.Sobrenome") %>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Button ID="btnAlterar"
                                runat="server"
                                CommandName="Alterar"
                                CommandArgument='<%# Eval("Id") %>'
                                Text="Alterar" />
                            <asp:Button ID="Excluir"
                                runat="server"
                                CommandName="Excluir"
                                CommandArgument='<%# Eval("Id") %>'
                                Text="Excluir" />
                        </ItemTemplate> 
                        <ItemStyle Wrap="false"
                            Width="1%"
                            HorizontalAlign="Center"
                            VerticalAlign="Middle" />
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <div>
                <asp:Button ID="btnIncluir"
                    runat="server"
                    OnClick="btnIncluir_Click"
                    Text="Incluir" />
            </div>
        </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger ControlID="btnFiltrar" />
        </Triggers>
    </asp:UpdatePanel>
</asp:Content>